﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.IO;
using System.Net;

namespace DealKhuyenMaiV2.com.Helpers
{
    public static class Utilities
    {
        private static readonly string[] VietnameseSigns = new string[]
 {
  "aAeEoOuUiIdDyY",
  "áàạảãâấầậẩẫăắằặẳẵ",
  "ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ",
  "éèẹẻẽêếềệểễ",
  "ÉÈẸẺẼÊẾỀỆỂỄ",
  "óòọỏõôốồộổỗơớờợởỡ",
  "ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ",
  "úùụủũưứừựửữ",
  "ÚÙỤỦŨƯỨỪỰỬỮ",
  "íìịỉĩ",
  "ÍÌỊỈĨ",
  "đ",
  "Đ",
  "ýỳỵỷỹ",
  "ÝỲỴỶỸ"
 };
        public static string RemoveVietnameseSign(this string str)
        {
            for (int i = 1; i < VietnameseSigns.Length; i++)
            {
                for (int j = 0; j < VietnameseSigns[i].Length; j++)
                    str = str.Replace(VietnameseSigns[i][j], VietnameseSigns[0][i - 1]);
            }
            return str;
        }
        public static double ToVietnamDong(this decimal input)
        {
            double db = Convert.ToDouble(input / 20);
            return db;
        }


        public static void SendEmail(string emailrecieved,string noidung)
        {


            var fromAddress = new MailAddress("dealkhuyenmaig2@gmail.com", "DealkhuyenmaiG2");
            const string fromPassword = "dealkhuyenmaig2"; //wtf

                const string subject = "Reset Password";
                string body = noidung;

                string toMailAddress = emailrecieved;
                string toMailDisplay = emailrecieved;

                var toAddress = new MailAddress(toMailAddress, toMailDisplay);

                var smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
                };

                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = body
                }
                )
                {
                    smtp.Send(message);
                }


        }

        public static void CreateFolder(string path)
        {
            Directory.CreateDirectory(path);
        }
    }
}